package com.xiaohai.wx.weather.util;

import java.io.IOException;
import java.util.Properties;
import java.util.logging.Logger;

import org.apache.commons.lang.StringUtils;

public class PropertiesUtil {

	private static Properties weixinProperties = null;

    private static final String WEIXIN_PROPERTIES = "/weixin.properties";

    private static Logger logger = Logger.getLogger(PropertiesUtil.class.getName());
    
    private static void loadProperties() throws IOException {
        
    	weixinProperties = new Properties();
    	weixinProperties.load(PropertiesUtil.class.getResourceAsStream(WEIXIN_PROPERTIES));
    }
    
    public static String getProperty (String propertyName) throws Exception {
    	
    	String propertyValue = null;	
    	
    	if(weixinProperties == null){
    		loadProperties();
    	}
    	
    	propertyValue = weixinProperties.getProperty(propertyName);
    	
    	if(!StringUtils.isBlank(propertyValue)){
    		return propertyValue;
    	}
    	
    	throw new Exception("Can't find property "+ propertyName +" in property files!");
    }
    
}
